package offer_test_20;

import java.util.Arrays;

//把一个数组最开始的若干个元素搬到数组的末尾，我们称之为数组的旋转。
//输入一个递增排序的数组的一个旋转，输出旋转数组的最小元素。例如
//数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转，该数组的最小值为1.
public class eight_MinNumBerInRotatedArray {
	public static void main(String[] args) {
		int[] array = { 1,0,1,1,1,1};
		findminnum(array);
	}

	public static void findminnum(int[] array) {
		int head = 0;
		int tail = array.length - 1;
		int min = 999;
		if (head == tail - 1 || head == tail) {
			System.out.println(array[head]);
		} else {
			if (array[head] > array[tail]) {
				head = (head + tail) / 2;
				findminnum(Arrays.copyOfRange(array, head, array.length));
			} else if(array[head]<array[tail]){
				tail = (head + tail) / 2;
				findminnum(Arrays.copyOfRange(array, 0, tail));
			}else{
				for(int i=0;i<array.length;i++){
					if (min>array[i]){min=array[i];} 
				}
				System.out.println(min);
			}
		}
	}
}
